package com.d0326;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TestHashMap {
    public static void main(String[] args) {
        Map<String,Student> studentMap=new HashMap<>();
        Student stu1 = new Student("Bright", 22, 100);
        Student stu2 = new Student("Win", 20, 95);
        Student stu3 = new Student("Jack", 25, 98);
                       //key value
        studentMap.put("B",stu1);
        studentMap.put("W",stu2);
        studentMap.put("J",stu3);
        studentMap.put("A",stu1);//key不同 value 可以相同
        studentMap.put("J",stu3);//重复的Key会被忽略掉

        //System.out.println(studentMap.size());

        //Student x1=studentMap.get("J");
        //System.out.println(x1);

        Set<String> keys=studentMap.keySet();
        for (String str:
             keys) {
            System.out.println(str+"------------>"+studentMap.get(str));
        }

        //key可以取得value,返过来不可以
        Collection<Student> values=studentMap.values();
        for (Student stu:
             values) {
            System.out.println(stu);
        }
        Set<Map.Entry<String,Student>> entrys=studentMap.entrySet();
        for (Map.Entry en:
             entrys) {
            System.out.println(en.getKey()+"--------------->"+en.getValue());
        }
    }
}
